<?php
/**
 * ============================================================================
 * 版权所有 2008-2011 多多网络，并保留所有权利。
 * 网站地址: http://soft.duoduo123.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
session_start();
include_once 'comm/config.php';
include_once 'comm/Taoapi.php';
include_once 'comm/page.class.php';
include_once 'plugins/nokeywords.php';
include_once 'comm/checkpostandget.php';
$no_words = include ('cache/no_words.php');
$tao_id_arr = include ('data/tao_ids.php');

$Taoapi_Config = Taoapi_Config::Init();
$Taoapi_Config->setCharset('UTF-8');
$Taoapi = new Taoapi;

$searchlimist=(int)SEARCHLIMIT;
if($searchlimist>0){
    if(time()-$_COOKIE['lastsearchtime']<=$searchlimist){
	    $list='_li';
	    $itemcatsname='搜索过于频繁';
        $tag="list";
        include_once 'comm/wjt.php';
        include_once 'comm/seo.php';
        $action_url="list.php";
        //引入模版文件
        include 'template/'.MOBAN.'/list.tpl.php';
        mysql_close();
	    exit;
    }
    setcookie("lastsearchtime", time(), time() + 100000);
}

$pagesize=PAGESIZE;

$page=empty($_GET['page'])?'1':intval($_GET['page']);
$q=empty($_GET['q']) ? '' : $_GET['q']; 
$s=(int)$_GET['s'];
$cid =decode_url(empty($_GET['cid'])?'':$_GET['cid']);
$cid=empty($_GET['cid']) ? '' :(int)$cid;
$search=(int)$_GET['search'];

$sort=empty($_GET['sort']) ? MORESORT : $_GET['sort']; 
$start_price=empty($_GET['start_price'])?'':(int)$_GET['start_price'];
$area=empty($_GET['area'])?'':($_GET['area']);
$end_price= empty($_GET['end_price'])?'':(int)$_GET['end_price'];
$guarantee=$_GET['guarantee'];
$nick=$_GET['nick'];
$list=$_GET['list'];
if($list!=''){$_SESSION['list']=$list;}
if($list==''){
	$list=$_SESSION['list'];
	if($list==''){$list=LIEBIAO;}
}
$list=(int)$list;

if($q=='请输入商品名称...'){$q='';}

if($q==''&&$cid==''){$q=HOTWORD;}
    

$Taoapi->method = 'taobao.taobaoke.items.get';
$Taoapi->fields = 'iid,num_iid,title,nick,pic_url,price,click_url,shop_click_url,commission,commission_rate,commission_num,commission_volume,volume,item_location';
$Taoapi->nick = MYUSERNICK;
$Taoapi->cid=$cid;
$Taoapi->keyword=$q;
$Taoapi->start_credit=$start_credit;
$Taoapi->end_credit=$end_credit;
$Taoapi->start_price=$start_price;
$Taoapi->end_price=$end_price;
$Taoapi->sort=$sort;
$Taoapi->area=$area;
$Taoapi->page_no=$page;
$Taoapi->page_size=$pagesize;
$Taoapi->outer_code = $_SESSION['dduserid'];
$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
$TaobaokeItem1 = $TaobaokeData["taobaoke_items"]["taobaoke_item"];
$TotalResults = $TaobaokeData["total_results"]; 
if (!$TotalResults){
	$s8_url = "http://s.taobao.com/search?q=".urlencode(iconv('UTF-8','GBK//IGNORE',$q))."&cat=$cid&ali_trackid=2:mm_".MYUSERPID."_0_0&search_type=item&unid=".$_SESSION['dduserid'];
}

if(!$TaobaokeItem1[0]){
	$TaobaokeItem2[0]=$TaobaokeItem1;
}else{
	$TaobaokeItem2=$TaobaokeItem1;
}

$c=count($TaobaokeItem2);
for($i = 0; $i < $c; $i++){
	if($i<=PAGESIZE){
		$TaobaokeItem[$i]=$TaobaokeItem2[$i];
	}else{
		$ListHot[$i-PAGESIZE-1]=$TaobaokeItem2[$i];
	}
}

//最多显示99页
if($TotalResults>$pagesize*99)
{
	$total=99*$pagesize;
}else
{
	$total=$TotalResults;
}
if($start_price=='0'){$start_price='';}
if($end_price=='999999'){$end_price='';}
//获取卖家昵称字符换
$strnicks = "";
$c=count($TaobaokeItem);
for($i = 0; $i < $c; $i++){
	if($i == 0){
		$strnicks = $TaobaokeItem[$i]["nick"]; 
	}else{
		$strnicks = $strnicks . "," . $TaobaokeItem[$i]["nick"]; 
	}
}

//获取卖家信息
$Taoapi->method = 'taobao.users.get';
$Taoapi->fields = 'user_id,nick,seller_credit,location,consumer_protection,type';
$Taoapi->nicks = $strnicks;
$TaoapiUsers = $Taoapi->Send('get','xml')->getArrayData();
$Result_users1 = $TaoapiUsers["users"]["user"]; 
if(!$Result_users1[0]){
	$Result_users[0]=$Result_users1;
}else{
	$Result_users=$Result_users1;
}
//网站头
$itemcatsname=$q;
//获取商品类目信息
if($itemcatsname==''){
	include("comm/title.php");
}

if($itemcatsname==''){
    $Taoapi->method = 'taobao.itemcats.get';
    $Taoapi->fields = 'name';
	$Taoapi->cids = $cid;
	$TaobaokeData = $Taoapi->Send('get','xml')->getArrayData();
	$data = $TaobaokeData["item_cats"]["item_cat"];
	$itemcatsname=$data['name'];
}

$c=count($TaobaokeItem);
for($i=0;$i<$c;$i++){
	if($TaobaokeItem[$i]["nick"]!="")
	{
		$TaobaokeItem[$i]["nick_url"]=urlencode($TaobaokeItem[$i]["nick"]);
		$TaobaokeItem[$i]["user_id"]=$Result_users[$i]["user_id"];
		$TaobaokeItem[$i]["type"]=$Result_users[$i]["type"];
		$TaobaokeItem[$i]["level"]=$Result_users[$i]["seller_credit"]["level"]; 
		$TaobaokeItem[$i]["state"]=$Result_users[$i]["location"]["state"]; 
		$TaobaokeItem[$i]["city"]=$Result_users[$i]["location"]["city"]; 
		
		foreach($no_words as $v){
            if(strpos($TaobaokeItem[$i]["title"],$v)!==false){
	            $TaobaokeItem[$i]["title"]=str_replace($v,'***',$TaobaokeItem[$i]["title"]);
	        }
        }
	}
}

$tag="list";
include_once 'comm/wjt.php';
include_once 'comm/seo.php';
$action_url="list.php";
//引入模版文件
include 'template/'.MOBAN.'/list.tpl.php';
mysql_close();
?>